import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.regex.Pattern;

public class Triangle2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		RunProgram();
		
	}
	
	private static void RunProgram()
	{
		try
		{
			System.out.println("This program determines if a triangle is equilateral, isosceles, or scalene based on user's input \n");
			
			float[] anArray;              
			anArray = new float[3];      
			boolean continueProgram = true;
			
			for (int i = 1; i <= 3; i++)
			{
				System.out.println("Enter triangle length of side " + i + ": ");
			    BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
			    String side = bufferRead.readLine();
			    
			    boolean isInteger = CheckInt(side);
			    boolean isEmptyString = CheckEmptyString(side);
	
			    // Check to see if input is a valid number. If not, keep prompting user to enter valid number
			    //while (!isInteger || isEmptyString)
			    //{
			    	if (isEmptyString)
			    	{
			    		System.out.println("Error: Need to enter a triangle side. Terminating program.");
					    //bufferRead = new BufferedReader(new InputStreamReader(System.in));
					    //side = bufferRead.readLine();
					    continueProgram = false;
					    break;
			    	}
			    	else if (!isInteger)
			    	{
				    	System.out.println("Error: Invaid triangle length. Terminating program.");
					    //bufferRead = new BufferedReader(new InputStreamReader(System.in));
					    //side = bufferRead.readLine();
					    continueProgram = false;
					    break;
			    	} 
			    	else if (!CheckBoundaries(side))
			    	{
			    		System.out.println("Error: Triangle length has to be greater than zero and less than or equal to 1 million. Terminating program.");
			    		continueProgram = false;
			    		break;
			    	} 
			    	else
			    	{
			    		anArray[i - 1] = Float.parseFloat(side);
			    	}
			    	//isEmptyString = CheckEmptyString(side);
			    	//isInteger = CheckInt(side);
			    //}
			    
			    //anArray[i - 1] = Float.parseFloat(side);

			}
			
			if (continueProgram)
			{
				String result = TriangleType(anArray);
			
				System.out.println(result + " Triangle");
			}
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	
	}
	
	private static boolean CheckInt(String inSide)
	{
		return Pattern.matches("-?\\d+(\\.\\d+)?", inSide);
	}
	
	private static boolean CheckEmptyString(String inSide)
	{
		return inSide.equals("");
	}
	
	private static boolean CheckBoundaries(String inSide)
	{
		float side = Float.parseFloat(inSide);
		
		return side > 0 && side <= 1000000;
	}
	
	private static boolean CheckValidTriangle(float[] anArray)
	{
		Arrays.sort(anArray);
		
		if (anArray[0] + anArray[1] <= anArray[2])
			return false;
		else
			return true;
	}
	
	private static boolean CheckRight(float a, float b, float c)
	{
		double result = Math.sqrt((a * a) + (b * b));

		DecimalFormat twoDForm = new DecimalFormat("#.##");
		result = Double.valueOf(twoDForm.format(result));

		
		if (result == Double.valueOf(twoDForm.format(c)))
			return true;
		else
			return false;

	}
	
	private static String TriangleType(float[] anArray)
	{
		String result = "";
		boolean isValid = CheckValidTriangle(anArray);
		
		if (!isValid)
		{
			result = "invalid. The sum of the shortest two sides of a triangle should be " +
					"greater than the length of the longest side of a triangle";
		
		} 
		else 
		{
			// Check if triangle is a right triangle
		    if (CheckRight(anArray[0], anArray[1], anArray[2]) ||
		    	CheckRight(anArray[1], anArray[2], anArray[0]) ||
		    	CheckRight(anArray[0], anArray[2], anArray[1]))
		    {
		    	result = "Right ";
		    } 
		    
			// Check if triangle is equilateral, scalene, or isosceles
		    if (anArray[0] == anArray[1] && anArray[1] == anArray[2] && anArray[0] == anArray[2])
		    {
		    	result += "Equilateral";
		    } 
		    else if (anArray[0] != anArray[1] && anArray[1] != anArray[2] && anArray[0] != anArray[2])
		    {
		    	result += "Scalene";
		    }
		    else 
		    {		    	
		    	result += "Isosceles";
		    }
		}
		return result;
	}
	

}
